package com.jinghua.treatment.service.impl;

import com.jinghua.treatment.common.Pager;
import com.jinghua.treatment.entity.SysAuthentication;
import com.jinghua.treatment.mapper.SysAuthenticationMapper;
import com.jinghua.treatment.mapper.SysDoctorMapper;
import com.jinghua.treatment.service.SysAuthenticationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 王兴光 on 2018/5/17.
 */
@Service
class SysAuthenticationServiceImpl implements SysAuthenticationService {
    @Resource
    private SysAuthenticationMapper sysAuthenticationMapper;
    @Resource
    private SysDoctorMapper sysDoctorMapper;
    @Override
    public int insert(SysAuthentication record) {
        return sysAuthenticationMapper.insert(record);
    }

    @Override
    public SysAuthentication selectByPrimaryKey(Integer doctorId) {
        return sysAuthenticationMapper.selectByPrimaryKey(doctorId);
    }

    @Override
    public int updateByPrimaryKey(SysAuthentication record) {
        return sysAuthenticationMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<SysAuthentication> getAuthenticationList(Pager pager) {
        List<SysAuthentication> authentications = new ArrayList<SysAuthentication>();
        for(SysAuthentication authentication : sysAuthenticationMapper.selectAll(pager)){
            authentication.setDoctor(sysDoctorMapper.selectByPrimaryKey(authentication.getDoctorId()));
            authentications.add(authentication);
        }
        return authentications;
    }
}
